<?php

class Drink {

    var $timestamp; //date of today for given time

    var $typeId = "";
    var $typeString = "";
    var $amount = "";

    public function setTime($time) {
        //create new date time
        $date = new DateTime();

        //parse the time
        $timePattern = "/^([0-1][0-9]|2[0-3]):([0-5][0-9])$/";  //24-hr : seconds
        preg_match($timePattern, $time, $matches);
        if (sizeof($matches) == 3) {
            $hrs = $matches[1];
            $sec = $matches[2];

            $date->setTime($hrs, $sec, 0);
            //echo "from parse: " . $date->getTimestamp();
        } else {
            //echo "couldn't parse, use default: " . $date->getTimestamp();
        }
        $this->timestamp = $date;
    }

    public function getDateTime() {
        return $this->timestamp->format('Y-m-d H:i:s');
    }

    public function getTime() {
        return $this->timestamp->format('H:i');
    }

    public function toXml() {
        return "<drink timestamp=\"" . $this->getTime() . "\" typeString=\"" . $this->typeString . "\" amount=\"" . $this->amount . "\"/>";
    }

}

?>